package com.webservice.impl;


import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.webservice.dao.Pub;
import com.webservice.dao.PubBaseDao;
import com.webservice.service.IBaseService;
import com.webservice.utils.DateTimeTool;
import com.webservice.utils.UUIDUtil;
import com.webservice.utils.VOXMLMapping;
import com.webservice.vo.IBaseVO;
import com.webservice.vo.impl.CustomToWMSVO;
import com.webservice.vo.impl.LogInterfaceVO;
/**
 * 
 * @author Andy
 * billtype:
 *
 */
@Service("C001")
public class Customer implements IBaseService {
	
	private static Logger logger = Logger.getLogger(Customer.class);

	@Override
	@Transactional(value = "txManager", isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, rollbackFor = { Exception.class })
	public String returnData(String xml,PubBaseDao baseDao,String ip){
		String intoUUID = UUIDUtil.getUUID();
		String outUUID = UUIDUtil.getUUID();
		// 成对标志
		String pairflag = DateTimeTool.getDateTimeString(new Date(),"yyyymmddHHmmss:sss").replace(":", "");
		String content=null;
		StringBuffer buffer=new StringBuffer();
		buffer.append(" select xx.buyerid code,xx.shopname name,xx.shopname shortname, ");
		buffer.append(" (select areaname from areainfo where areaid=xx.province) province,  ");
		buffer.append(" (select areaname from areainfo where areaid=xx.city) city,  ");
		buffer.append(" (select areaname from areainfo where areaid=xx.county) area, ");
		buffer.append(" xx.companyaddress address,xx.pri_name contact,xx.pri_mobile phone,rl.outerid sourcesys,'NC' sourcecode  ");
		buffer.append("  from buyerinfo  xx ");
		buffer.append(" inner join relation_buyerother rl on rl.buyerid=xx.buyerid ");
		buffer.append(" where xx.buyerid=44691 ");
		logger.debug("__________________查询sql:"+buffer.toString());
		List<IBaseVO> list = null;
		try {
			list = baseDao.query(buffer.toString(), CustomToWMSVO.class);
		} catch (Exception e) {
			e.printStackTrace();
			content="查询sql是错误"+e.getMessage();
		}
		String insertxml = null;
		try {
			insertxml = VOXMLMapping.toXML(list.get(0), null, true ? "A":"U");
		} catch (Exception e) {
			e.printStackTrace();
			content="xml转化时出错"+e.getMessage();
		}
		logger.debug("__________________客户信息的xml:"+insertxml);
		//LogInterfaceVO logvo=new LogInterfaceVO(Pub.getCurrTime(),intoUUIDip,"01","44691","into",insertxml,pairflag);
		//logger.debug("__________________插入信息:"+logvo.toString());
		try {
			//baseDao.insert(logvo);
		} catch (Exception e) {
			e.printStackTrace();
			content="日志记录时出错"+e.getMessage();
		}
		return content==null?insertxml:content;
	}

}
